#include "stdafx.h"
#include "ccube.h"
#include <soil.h>
#pragma comment(lib,"SOIL.lib")

CCube::CCube()
{
	m_px = 0;
	m_py = 0;
	m_pz = 0;
	m_pitch = 0;
	m_yaw = 0;
	m_roll = 0;
	m_sx = 0;
	m_sy = 0;
	m_sz = 0;
	m_r = 0;
	m_g = 0;
	m_b = 0;
}

CCube::~CCube()
{
}

void CCube::draw()
{
	glMatrixMode (GL_MODELVIEW);
	glPushMatrix();

	glTranslatef(m_px,m_py,m_pz);
	glScalef(m_sx,m_sy,m_sz);

	//material
	GLfloat vector[4]={m_r,m_g,m_b,1.0};
	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,vector);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, m_idTexture);

	glBegin (GL_QUADS);

	//1er cuadrado
	glNormal3f(0,0,1);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0,0,1);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1,0,1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1,1,1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(0,1,1);
	//2o cuadrado
	glNormal3f(0,0,-1);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0,0,0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0,1,0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1,1,0);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1,0,0);	
	//3er cuadrado
	glNormal3f(1,0,0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(1,0,1);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1,0,0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1,1,0);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1,1,1);
	//4o cuadrado
	glNormal3f(-1,0,0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0,0,0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0,0,1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(0,1,1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(0,1,0);
	//5o cuadrado
	glNormal3f(0,1,0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0,1,0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(0,1,1);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1,1,1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(1,1,0);
	//6o cuadrado
	glNormal3f(0,-1,0);
	glTexCoord2f(0.0,1.0);
	glVertex3f(0,0,0);
	glTexCoord2f(1.0,1.0);
	glVertex3f(1,0,0);
	glTexCoord2f(1.0,0.0);
	glVertex3f(1,0,1);
	glTexCoord2f(0.0,0.0);
	glVertex3f(0,0,1);

	glEnd();

	glPopMatrix();
}

void CCube::setPosition(int x, int y, int z) {
	m_px = x;
	m_py = y;
	m_pz = z;
}

void CCube::setRotation(double pitch, double yaw, double roll) {
	m_pitch = pitch;
	m_yaw = yaw;
	m_roll = roll;
}

void CCube::setScale(double x, double y, double z) {
	m_sx = x;
	m_sy = y;
	m_sz = z;
}

void CCube::setColor(int r, int g, int b) {
	m_r = r;
	m_g = g;
	m_b = b;
}

void CCube::setTexture(int textura) {
	m_idTexture = textura;
}